package site

import (
	"context"
	"git.mycaigou.com/gfyx/common/tenant_db"
	"gorm.io/gorm"
)

type siteRepo struct {
	tenant_db.TenantDB
}

func NewSiteRepository() SiteRepositoryIface {
	return &siteRepo{}
}

func (s *siteRepo) SaveSiteInfo(ctx context.Context, siteInfo *SiteInfoPo) error {
	if err := s.GetTenantDB(ctx).Save(siteInfo).Error; err != nil {
		return err
	}
	return nil
}

func (s *siteRepo) GetSiteInfo(ctx context.Context) (*SiteInfoPo, error) {
	siteInfo := SiteInfoPo{}
	err := s.GetTenantDB(ctx).First(&siteInfo).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return nil, err
	}
	return &siteInfo, nil
}
